﻿namespace EFS.RC.CC.Messages
{
	/// Used for the statuses message list
	public class MessageCollection<T> : EFS.RC.CC.Messages.Message, System.Collections.IEnumerable
		where T : EFS.Common.Serialization.ISerializable
	{
		/// <summary>
		/// internal list
		/// </summary>
		public EFS.Common.Serialization.SerializableCollection<T> Items { get; private set;}

		/// <summary>
		/// Constructor
		/// </summary>
		public MessageCollection()
		{
			Items = new Common.Serialization.SerializableCollection<T>();
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="items"></param>
		public MessageCollection(T[] items)
		{
			Items = new Common.Serialization.SerializableCollection<T>(items);
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="collection"></param>
		public MessageCollection(System.Collections.Generic.ICollection<T> collection)
		{
			Items = new Common.Serialization.SerializableCollection<T>(collection);
		}

		/// Serialize
		public override void Serialize(EFS.Common.Serialization.XmlWriter xmlWriter)
		{
			// write
			Items.Serialize(xmlWriter);
		}

		/// Deserialize
		public override void Deserialize(EFS.Common.Serialization.XmlReader xmlReader)
		{
			Items.Deserialize(xmlReader);
		}

		/// <summary>
		/// Get enumerator
		/// </summary>
		/// <returns></returns>
		public System.Collections.IEnumerator GetEnumerator()
		{
			return Items.GetEnumerator();
		}
	}
}